# -*- encoding: utf-8 -*-
"""
File Name: launch
Description:
Author : 'lirui'
date: 2024/2/7
Contact: marjey_lee@163.com
Change Activity:
2024/2/7:
"""
from projects.monitoring.alarm_manager.modules.monitor_agent_health_check.check import CheckService
from projects.monitoring.alarm_manager.services.alarm_manager import AlarmManager
import uvicorn
from fastapi import FastAPI
from starlette.middleware.cors import CORSMiddleware

_APP = FastAPI()

_APP.add_middleware(
    CORSMiddleware,
    allow_origins=['*'],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)
_SERVICE = AlarmManager()
_SERVICE.subscribe()
_AGENT_HEALTH_CHECK = CheckService()
_AGENT_HEALTH_CHECK.start()


@_APP.get("/health_check")
async def main():
    return _SERVICE.health_check()


def _main():
    uvicorn.run(_APP, host="0.0.0.0", port=8080)


if __name__ == '__main__':
    _main()
